package com.ruoyi.web.controller.pv;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.pv.domain.PvClassScore;
import com.ruoyi.pv.service.IPvClassScoreService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 培训班分值Controller
 *
 * @author zzx
 * @date 2023-06-14
 */
@RestController
@RequestMapping("/system/class_score")
public class PvClassScoreController extends BaseController {
    @Autowired private IPvClassScoreService pvClassScoreService;

    /**
     * 查询培训班分值列表
     */
    @PreAuthorize("@ss.hasPermi('system:class_score:list')")
    @GetMapping("/list")
    public TableDataInfo list(PvClassScore pvClassScore) {
        startPage();
        List<PvClassScore> list = pvClassScoreService.selectPvClassScoreList(pvClassScore);
        return getDataTable(list);
    }

    /**
     * 导出培训班分值列表
     */
    @PreAuthorize("@ss.hasPermi('system:class_score:export')")
    @Log(title = "培训班分值", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PvClassScore pvClassScore) {
        List<PvClassScore> list = pvClassScoreService.selectPvClassScoreList(pvClassScore);
        ExcelUtil<PvClassScore> util = new ExcelUtil<PvClassScore>(PvClassScore.class);
        util.exportExcel(response, list, "培训班分值数据");
    }

    /**
     * 获取培训班分值详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:class_score:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(pvClassScoreService.selectPvClassScoreById(id));
    }

    /**
     * 新增培训班分值
     */
    @PreAuthorize("@ss.hasPermi('system:class_score:add')")
    @Log(title = "培训班分值", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PvClassScore pvClassScore) {
        return toAjax(pvClassScoreService.insertPvClassScore(pvClassScore));
    }

    /**
     * 修改培训班分值
     */
    @PreAuthorize("@ss.hasPermi('system:class_score:edit')")
    @Log(title = "培训班分值", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PvClassScore pvClassScore) {
        return toAjax(pvClassScoreService.updatePvClassScore(pvClassScore));
    }

    /**
     * 删除培训班分值
     */
    @PreAuthorize("@ss.hasPermi('system:class_score:remove')")
    @Log(title = "培训班分值", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(pvClassScoreService.deletePvClassScoreByIds(ids));
    }
}
